package cloud.controller;

import cloud.pojo.Orders;
import cloud.service.OrdersService;

import com.liumuxian.base.service.IntegralDataService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import util.IdWorker;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    OrdersService ordersService;
    @Autowired
    IntegralDataService integralDataService;
    @Autowired
    IdWorker idWorker;
    @RequestMapping("/save")
    public String save(Orders orders,Integer integral){
        orders.setId(idWorker.nextId()+"");
        integralDataService.saveorders(integral,orders.getUserid(),orders.getId());
        ordersService.save(orders);
        return null;
    }

    @RequestMapping("/updatetopage")
    public String updatetopage(String id){
        ordersService.updatetopage(id);
        return null;
    }

    @RequestMapping("/updates")
    public String updates(Orders orders){
        ordersService.updates(orders);
        return null;
    }

    @RequestMapping("/findAll")
    @ResponseBody
    public Page<Orders> findAll(Integer pagesize, Integer pagenumber, Orders orders) throws Exception{
        return ordersService.findAll(pagesize,pagenumber,orders);
    }


    @RequestMapping("/deletes")
    public String deletes(String id){
        ordersService.deletes(id);
        return null;
    }

    @RequestMapping("/shoppurc")
    @ResponseBody
    public Result shoppurc(@RequestParam HashSet<String> shopid, @RequestParam String userid){
        System.out.println(shopid);
        HashMap<String,String> hashMap=ordersService.shoppurc(shopid,userid);
        return new Result(true, StatusCode.OK,"查询成功！",hashMap);
    }
}
